From 2afbe6c4bb0b724b526b69f81598ff96f3fe1216 Mon Sep 17 00:00:00 2001 From: robertl Date: Sat, 15 Apr 2006 19:16:26 +0000 Subject: [PATCH] Sketch in a function to recompute "track things" such as speed and heading. --- route.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/route.c b/route.c index 6c07cb285..b13a05da1 100644 --- a/route.c +++ b/route.c @@ -19,6 +19,7 @@ #include #include "defs.h" +#include "grtcirc.h" static queue my_route_head; static queue my_track_head; @@ -436,3 +437,31 @@ track_restore( queue *head_bak) common_restore_finish(); } + +/* + * This really makes more sense for tracks than routes. + * Run over all the trackpoints, computing heading (course), speed, and + * and so on. + */ +void track_recompute(route_head *trk) +{ + waypoint first; + waypoint *this; + waypoint *prev = &first; + queue *elem, *tmp; + + first.latitude = 0; + first.longitude = 0; + first.creation_time = 0; + + QUEUE_FOR_EACH((queue *)&trk->waypoint_list, elem, tmp) { + this = (waypoint *)elem; + this->course = heading(prev->latitude, prev->longitude, + this->latitude, this->longitude); + this->speed = radtometers(gcdist( + RAD(prev->latitude), RAD(prev->longitude), + RAD(this->latitude), RAD(this->longitude))) / + labs(this->creation_time - prev->creation_time); + prev = this; + } +} -- 2.30.2